
let level = [
    {
        call: "用药安全专家",
        img: "static/img/level1.png"
    },
    {
        call: "家庭小医生",
        img: "static/img/level4.png"
    },
    {
        call: "药师小学徒",
        img: "static/img/level3.png"
    },
    {
        call: "绝命毒师",
        img: "static/img/level2.png"
    },
]
import { wxShare } from '@/utils'
import $ from 'jquery'
import html2canvas from "html2canvas"
import commonFn from "@/utils/commonFn/index"
export default {
    name: "",
    data() {
        return {
            imgSrc: "",
            userName: "",
            rightNum: 5,
            level: level,
            addName: true,
            callName: '用药安全专家',
            levelImg: '',
            date: '',
            time: '',
            showMask: false,
            scale: 0,
            isIOS: false,
            isBuild: false
        };
    },
    methods: {
        buildImg() {
            if (this.isBuild) return
            var dom = document.getElementById("html-img");
            html2canvas(dom, {
                useCORS: true,
                allowTaint: false
            }).then(canvas => {
                this.imgSrc = canvas.toDataURL("image/jpeg");
                $('#view').remove()
                this.addName = false
            });

        },
        build() {
            if (!this.userName) {
                this.$vux.toast.text("请输入您的姓名", "top");
                return
            }
            if (this.userName.length >= 5) {
                this.$vux.toast.text("请输入正确的姓名", "top");
                return
            }

            this.$router.push({
                path: '/buildimg',
                query: {
                    allRightNum: this.rightNum,
                    userName: this.userName
                }
            })
        },
        percentage(rightNum) {
            switch (Number(rightNum)) {
                case 10:
                    return '90'
                    break;
                case 9:
                    return '80'
                    break;
                case 8:
                    return '70'
                    break;
                case 7:
                    return '60'
                    break;
                case 6:
                    return '50'
                    break;
                case 5:
                    return '40'
                    break;
                case 4:
                    return '30'
                    break;
                case 3:
                    return '20'
                    break;
                case 2:
                    return '10'
                    break;
                case 1:
                    return '5'
                    break;
                case 0:
                    return '0'
                    break;
                default:
                    break;
            }
        },
        hideMask() {
            this.showMask = false
        },
        downLoad() {
            window.location.href = 'https://app.allclinic.cn/h5/#/clients/download'
        },
        again() {
            this.$router.push('/')
        },
        share() {
            // wxShare({
            //     title: "乱吃药严重可危及生命，测一测你的用药安全意识",
            //     text: `10道常用药安全测试题，99%的人都答错，无知很可怕，测一测你的用药安全意识`,
            //     href: 'http://app.allclinic.cn/h5/wx/startActivity/#/',
            //     imgUrl:
            //         "https://app.allclinic.cn/h5/wx/scan_drug/static/img/logo.jpg"
            // });
        }
    },
    filters: {
        result(newValue) {
            if (newValue == 10) {
                return '恭喜你全部答对了！'
            } else {
                return `恭喜你答对${newValue}题`
            }
        },
        percentage(newValue) {

        }
    },
    mounted() {
        window.localStorage.clear();
        this.$vux.toast.text("缓存清除成功！", "top");
    }
};
